#pragma once

#include <fstream>
#include <iostream>
#include <string>
#include "Biome Definitions.h"
#include "_generator definitions.h"

class _Biome {
private:
public:
	//FirstByte is the Variation
	// How many itterations before it "can" switch lastXDirs
	//  (Set number)
	//SecondByte is the MaxMove
	// How much higher or lower the next block can be
	//ThirdByte is the Frequency
	// How often the height is willing to change
	//  (Percentage)
	//FourthByte is NULL for now
	int ToolData[E_TOOL_SIZE];
	bool ToolSet[E_TOOL_SIZE];

	_Biome() {
		for(int i = E_TOOL_SIZE-1;i >= 0;i--) {
			ToolSet[i] = false;
			ToolData[i] = 0;
		}
	}

	void CreateBiome(char * File) {
		int iBuffer;
		std::ifstream in;
		in.open(File,std::ios::app);

		while(!in.eof()) {
			in >> iBuffer;
			switch(iBuffer) {
			case E_TOOL_RANDOM: // Random Ground
				if(E_TOOL_RANDOM < E_TOOL_SIZE)
					ToolSet[E_TOOL_RANDOM] = true;
				ReadData(in,ToolData[E_TOOL_RANDOM]);
				break;
			case E_TOOL_CAVE:
				if(E_TOOL_CAVE < E_TOOL_SIZE)
					ToolSet[E_TOOL_CAVE] = true;
				//ReadData(in,ToolData[E_TOOL_CAVE]);
				break;
			case E_TOOL_GRASS: // ApplyGrass
				if(E_TOOL_GRASS < E_TOOL_SIZE)
					ToolSet[E_TOOL_GRASS] = true;
				ReadData(in,ToolData[E_TOOL_GRASS]);
				//Doesn't need any info
				break;
			case E_TOOL_STONE: // ApplyStone
				if(E_TOOL_STONE < E_TOOL_SIZE)
					ToolSet[E_TOOL_STONE] = true;
				ReadData(in,ToolData[E_TOOL_STONE]);
				//Doesn't need any info
				break;
			case E_TOOL_TREES:
				if(E_TOOL_TREES < E_TOOL_SIZE)
					ToolSet[E_TOOL_TREES] = true;
				ReadData(in,ToolData[E_TOOL_TREES]);
				break;
			case E_TOOL_ORE1:
				if(E_TOOL_ORE1 < E_TOOL_SIZE)
					ToolSet[E_TOOL_ORE1] = true;
				ReadData(in,ToolData[E_TOOL_ORE1]);
				break;
			default: break;
			}
		}

		in.close();
	}

	void ReadData(std::ifstream & in,int & output) {
		int iBuffer;
		in >> iBuffer;
		output |= iBuffer;
		in >> iBuffer;
		output |= TREAT_FIRST_AS_SECOND_BYTE(iBuffer);
		in >> iBuffer;
		output |= TREAT_FIRST_AS_THIRD_BYTE(iBuffer);
		in >> iBuffer;
		output |= TREAT_FIRST_AS_FOURTH_BYTE(iBuffer);
	}

}typedef BIOME,* PBIOME;